package com.doctor.ui.wxapi;

import android.content.Context;

import com.doctor.comm.MyApplication;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

/**
 * 微信api的辅助类
 */

public class MyWXApi {
	
	private static final String APP_ID = "wx7d9c96ce65967ea6";
	//第三方app与微信通讯的openapi接口
	private static IWXAPI api;
	
	
	/**
	 * 防止被外部构造
	 */
	private MyWXApi(){
		
	}
	
	
	/**
	 * 将应用注册到微信
	 * @param context
	 */
	public static void regToWx(Context context) {
		api = WXAPIFactory.createWXAPI(context, APP_ID, false);
		boolean success = api.registerApp(APP_ID);
	}

	/**
	 * 获取IWXAPI的实例
	 * @return
	 */
	public static IWXAPI getWXApi(){
		if (api == null) {
			regToWx(MyApplication.getInstance());
		}
		return api;
	}
	
	
	/**
	 * 微信是否可用(微信是否已安装且支持微信 api)
	 * @return
	 */
	public static boolean canUseWX() {
		return getWXApi().isWXAppInstalled() && getWXApi().isWXAppSupportAPI();
	} 
	
}
